<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <title>WebGPU Example</title>
    <script src="../build-web/app.js"></script>
  </head>

  <body>
    <canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
    <div id="error" style="color: red;"></div>
    <script>
      function showError(message) {
        document.getElementById('error').innerText = message;
      }

      window.Module = null;
      async function initWebGPU() {
        if (!navigator.gpu) {
          showError("WebGPU is not supported in this browser.");
          return;
        }
        const adapter = await navigator.gpu.requestAdapter();
        if (!adapter) {
          showError("No WebGPU adapter found.");
          return;
        }
        const device = await adapter.requestDevice();
        Module.lmlm = 1234;
        Module.preinitializedWebGPUDevice = device;
        // Module.call('init', null, [], []);
        Module._init();
      }

      // Instantiate the Emscripten module
      createModule().then(m => {
        window.Module = m;
        initWebGPU();
      });
    </script>
  </body>

</html>
